<!DOCTYPE html>
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">


<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
</head>
<body>
<button type="button" th:onclick="sendmessage()">发送验证码</button>
<input type="text" id="input_code"/>
<button type="button"th:onclick="checkCode()">验证</button>
<script>
    sendmessage=()=>{
        var resultjson;
        $.ajax(
            {
                url: "http://localhost:8080/sendmessage",
                type: "GET",
                async:false,
                dataType:'text',
                success: function (result) {
                    resultjson=result;
                },
                error: function ( status) {
                    console.log("error")
                }
            });
        if (resultjson=='success'){
            alert("短信发送成功");
        }else{
            alert("短信发送失败，请联系管理员处理")
        }
    }
    checkCode=()=>{
        var resultjson;
        var input_code=$("#input_code").val();
        $.ajax({
            url: "http://localhost:8080/checkCode",
            type: "GET",
            async:false,
            dataType:'text',
            data:{inputCode:input_code},
            success: function (result) {
                resultjson=result;
            },
            error: function ( status) {
                console.log("error")
            }
        });
        if (resultjson=='success'){
            alert("验证成功");
        }else{
            alert("验证失败，验证码错误")
        }
    }

</script>
</body>
</html>